﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class hydevmanager_admin_manager_news : System.Web.UI.Page
{
  
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["timeout"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                if (Session["NameGroup"] == null)
                {
                    Response.Redirect("login.aspx");
                }
                else
                {

                    string NameGroup = Session["NameGroup"].ToString();
                    load_data_to_grAllMenu();
                    check_an_hien(NameGroup);
                }
            }
        }
    }
    protected void check_an_hien(string namegroup)
    {
        DataTable dtcheckan = new DataTable();
        dtcheckan = DataAccess.ExeSQLToDataTable("select * from dev_news where vemaybay=1  order by idnews desc");
        int n = dtcheckan.Rows.Count;
        
        if (n>0)
        {
            grAllNews.DataSource=dtcheckan;
            grAllNews.DataBind();
            for (int i = 0; i <n; i++)
            {
                if (namegroup == "Kỹ thuật")
                {
                    LinkButton linknoidung = (LinkButton)grAllNews.Rows[i].FindControl("lbnoidung");
                    linknoidung.Enabled = false;
                }
                else
                {
                    if (namegroup == "Nội dung")
                    {
                        LinkButton linkkythuat = (LinkButton)grAllNews.Rows[i].FindControl("lbkythuat");
                        linkkythuat.Enabled = false;
                    }
                    else
                    {
                        LinkButton linknoidung = (LinkButton)grAllNews.Rows[i].FindControl("lbnoidung");
                        linknoidung.Enabled = false;
                        LinkButton linkkythuat = (LinkButton)grAllNews.Rows[i].FindControl("lbkythuat");
                        linkkythuat.Enabled = false;
                        LinkButton linkhot = (LinkButton)grAllNews.Rows[i].FindControl("lkhot");
                        linkhot.Enabled = false;
                        LinkButton    linktop = (LinkButton)grAllNews.Rows[i].FindControl("lktop");
                        linktop.Enabled = false;
                        LinkButton linkdelete = (LinkButton)grAllNews.Rows[i].FindControl("lkdelete");
                        linkdelete.Enabled = false;
                         //linktop = (LinkButton)grAllNews.Rows[i].FindControl("lktop");
                    }
                }
            }
        }
      
    }
    protected void load_data_to_grAllMenu()
    {
        int checktour = 1;
        DataTable dtnews = DataAccess.ExeSQLToDataTable("SELECT * FROM dev_news  where vemaybay=1 ORDER BY idnews DESC");
        grAllNews.DataSource = dtnews;
        grAllNews.DataBind();
    }

    protected void news_grAll_click(object sender, CommandEventArgs e)
    {
        string Argvalue = e.CommandArgument.ToString();
        char[] ch = new char[] { '|' };

        string[] s = ITNLip.SplitString(Argvalue, ch);
        string id = s[0];
        string action = s[1];
        string value = s[2];
        if (Session["Name"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            string username = Session["Name"].ToString();
            switch (action)
            {
                case "top":
                    string istop = "0";
                    if (value == "False")
                    {
                        istop = "1";
                    }
                    DataAccess.ExeNonSQL("UPDATE dev_news SET istop='" + istop + "' WHERE idnews=" + id + "");
                    break;
                case "hot":
                    string ishot = "0";
                    if (value == "False")
                    {
                        ishot = "1";
                    }
                    DataAccess.ExeNonSQL("UPDATE dev_news SET ishot='" + ishot + "' WHERE idnews=" + id + "");
                    break;
                case "browrs":
                    string status = "0";
                    if (value == "False")
                    {
                        status = "1";
                    }
                    DataAccess.ExeNonSQL("UPDATE dev_news SET status='" + status + "',updatebykt=N'" + username + "' WHERE idnews=" + id + "");
                    break;
                case "ktnd":
                    string status1 = "0";
                    if (value == "False")
                    {
                        status1 = "1";
                    }
                    DataAccess.ExeNonSQL("UPDATE dev_news SET status1='" + status1 + "',updatebynd=N'" + username + "' WHERE idnews=" + id + "");
                    break;
                case "delete":

                    DataAccess.ExeNonSQL("DELETE FROM dev_news WHERE idnews=" + id + "");
                    break;
            }
        }
      
        string NameGroup = Session["NameGroup"].ToString();
        load_data_to_grAllMenu();
        check_an_hien(NameGroup);

    }


    //===============INTERFACE PUBLIC STATIC======================================================================
    //#region Hàm Public interface
    public static string test_has_menu_child(bool value, int IdMenu)
    {
        string htmlCode = "<a><img alt='' title='Can not Add' src='style/img/warning_16.png' /></a>";
        if (value == false)
        {
            htmlCode = "<a href='admin_add_menu.aspx?IdMenu=" + IdMenu + "'><img alt='' title='Click for Add SubMenu' src='style/img/add_16.png' /></a>";
        }
        return htmlCode;
        //HttpContext.Current.Request.QueryString.Get("");
    }

    public static string test_infor_menu(bool value, int IdMenu)
    {
        string htmlCode = "<a><img alt='' title='No Information' src='style/img/error_button_16.png' /></a>";
        if (value == true)
        {
            htmlCode = "<a href='admin_manager_menu.aspx?IdParent=" + IdMenu + "'><img alt='' title='Click for Information' src='style/img/info_button_16.png' /></a>";
        }
        return htmlCode;
    }

    public static string test_browrs_menu(bool value)
    {
        string htmlCode = "menu_browrs_off";
        if (value == true )
        {
            htmlCode = "menu_browrs_on";

        }
        return htmlCode;
    }
   
    public static string test_cant_delete(bool value)
    {
        string htmlCode = "<img alt='' src='style/img/close_16.png' title='Click to Delete' />";
        if (value == true)
        {
            htmlCode = "<img alt='' src='style/img/close_off_16.png' title='Can not Delete' />";
        }

        return htmlCode;
    }

    public static bool bool_inverse(bool value)
    {
        bool set = false;
        if (value == false)
        {
            set = true;
        }
        return set;
    }
    //#endregion
}